//
//  ContactsCell.m
//  AAIM
//
//  Created by awh on 2019/11/24.
//  Copyright © 2019年 AAIM. All rights reserved.
//

#import "ContactsCell.h"

@implementation ContactsCell

- (void)awakeFromNib {
    [super awakeFromNib];
     self.nameLbl.textColor=KHEXCOLOR(kBlackColor);
//    self.iconImage.backgroundColor=[UIColor redColor];
    self.selectionStyle = UITableViewCellStyleDefault;
    [self.contentView addSubview:self.line];
          
    [_line mas_makeConstraints:^(MASConstraintMaker *make) {
               make.left.equalTo(self.iconImage.mas_right).offset(SCALAE_WIDTH(10));
               make.bottom.equalTo(self.mas_bottom);
               make.height.offset(0.5);
               make.right.equalTo(self.mas_right).offset(SCALAE_WIDTH(-15));
           }];
    [self.iconImage configLayerWithBorderWidth:0 andWithCornerRadius:20 andWithBorderColor:[UIColor clearColor]];
    // Initialization code
}
-(void)setContactor:(ContactModel *)contactor
{
    if ([_cellType isEqualToString:@"friend"]) {
        _nameLbl.text = contactor.nickname;
//        NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",userHeaderImage,contactor.head]]];
//        _iconImage.image = [UIImage imageWithData:data];

        [_iconImage sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",userHeaderImage,contactor.head]] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
            KWeakSelf;
            if (!error) {
                weakSelf.iconImage .image = image;
            }else
            {
                weakSelf.iconImage.image =kHeadPlaceholderImage;
            }
        }];
        
//        [_iconImage sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",userHeaderImage,contactor.head]] placeholderImage:kHeadPlaceholderImage options:SDWebImageRefreshCached];
//
    }else
    {
//        NSLog(@"=地址====%@",userHeaderImage);
        _nameLbl.text = contactor.groupName;
//        NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",userHeaderImage,contactor.groupHead]]];
//        _iconImage.image = [UIImage imageWithData:data];
        [_iconImage sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",userHeaderImage,contactor.groupHead]] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
            KWeakSelf;
            if (!error) {
                weakSelf.iconImage .image = image;
            }else
            {
                weakSelf.iconImage.image =kHeadPlaceholderImage;
            }
        }];
    }
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (UIView *)line{
    if (!_line) {
        _line = [[UIView alloc]init];
        _line.backgroundColor = KHEXCOLOR(@"#E0E0E0");
    }
    return _line;
}

@end
